<?php

namespace app\admin\model;

use think\Model;

class VideoList extends Model
{
    protected $autoWriteTimestamp = true;

    protected $pk = 'video_id';

    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        $page = input('get.page');
        if ($search = input('get.video_title')) $where[] = ['a.video_title', 'like', "%" . $search . "%"];
        if (input('get.level_id')) $where[] = ['a.level_id', '=', input('get.level_id')];
        $list = self::alias('a')
            ->join('video_level b', 'a.level_id = b.level_id')
            ->join('video_category vc', 'a.category_id = vc.category_id', 'left')
            ->order('a.video_id', 'desc')
            ->where($where)
            ->field('a.*,b.level_title,vc.category_title')
            ->paginate($limit);
        foreach ($list as $k => $v) {
            $list[$k]['category_title'] = $v['category_title'] ?: '-';
        }
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit, 'page' => $page]];
    }

    public static function getTrainVideoList()
    {
        return self::alias('a')
            ->join('video_category b', 'a.category_id = b.category_id')
            ->where('a.video_status', 1)
            ->field('a.video_id,a.video_title')
            ->select()
            ->toArray();
    }
}